/*
 * @Title: community
 * @Description: TODO
 * @author MI
 * @date 2022/7/25 10:19
 * @version
 */
package com.shanshan.community.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author MI
 * @ClassName: CookieUtil
 * @Description: 获取cookie的工具类
 * @date 2022/7/25 10:19
 */
public class CookieUtil {

    public static String getValue(HttpServletRequest request, String cookieName) {
        //判空
        if (request == null || cookieName == null) {
            throw new IllegalArgumentException("参数为空！！");
        }
        //遍历cookie
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals("ticket")) {
                    return cookie.getValue();
                }
            }
        }
        return null;
    }
}
